package com.defangit.award.extend.wxmp;

import com.defangit.award.domain.WinningInfo;
import com.defangit.award.extend.point.WinningInfoListener;
import com.defangit.openapis.wechat.mp.message.template.AbstractTemplateMessage;
import com.defangit.openapis.wechat.mp.message.template.AwardResultTmplMessage;
import com.defangit.openapis.wechat.mp.message.template.TemplateData;
import org.slf4j.LoggerFactory;


/**
 * Created by zhangfagen on 2019/1/12.
 */
public class WxmpWinningInfoListener extends WinningInfoListener {
    @Override
    public boolean afterAnnounce(WinningInfo prize) {
        try {
            AbstractTemplateMessage msg = new AwardResultTmplMessage()
                    .setData(new AwardResultTmplMessage.AwardResultData()
                            .setAward(TemplateData.orangeData().setValue(prize.getPrize().getAward().getAwardName()))
                            .setCashWay(TemplateData.orangeData().setValue("到店凭抽奖记录兑奖"))
                            .setCongratulation(TemplateData.orangeData().setValue("恭喜您已中奖"))
                            .setPrize(TemplateData.orangeData().setValue(prize.getPrize().getPrizeName()))
                            .setEndTime(TemplateData.orangeData().setValue(prize.getWinTime().toString()))
                            .setRemark(TemplateData.orangeData().setValue(prize.getPrize().getPrizeDetail()))
                    ).setTemplateId("f3rPfibwqC9cHQOcqnzpUNOdrpYOQ20IIazsavfkBUY")
                    .setTopcolor("#00ff00")
                    .setTouser(prize.getOpenId());
            WxmpPluginEntry.getWechat("zm").messageManager().sendTemplateMessage(msg);
        }catch (Exception ex){
            LoggerFactory.getLogger(WxmpWinningInfoListener.class).error(ex.getLocalizedMessage(),ex);
        }
        return true;
    }
}
